﻿using B.S.DataBase.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.Write.API.Appicant.Command.MeonCommand;
using MediatR;

namespace B.S.DataBase.Write.API.Appicant.CommandHandler.MeonCommandHandler
{
    public class MeonUpdateCommdHanders : IRequestHandler<MeonUpdateCommder, APIResult<string>>
    {

        private readonly IBaseRepository<TrunMeon> baseRepository;

        public MeonUpdateCommdHanders(IBaseRepository<TrunMeon> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public async Task<APIResult<string>> Handle(MeonUpdateCommder request, CancellationToken cancellationToken)
        {
            APIResult<string> result =new APIResult<string>();

            result.Code = APIEnum.修改成功;
            result.Msg =APIEnum.操作成功.ToString();
            var obj = baseRepository.GetAll().Result.FirstOrDefault(x => x.Trunid == request.Trunid);
            obj.Name = request.Name;
            obj.DepId= request.DepId;
            obj.IeaveType = request.IeaveType;
            obj.StartDate = request.StartDate;
            obj.EndDate = request.EndDate;
            obj.TotalDays = request.TotalDays;
            obj.TotalHours = request.TotalHours;
            obj.ReportDate = request.ReportDate;
            obj.Reason = request.Reason;
            obj.Ieader = request.Ieader;

            baseRepository.Update(obj);

            return await Task.FromResult(result);


        }
    }
}
